<?php
/*
 *	APP接口模块
 */
namespace app\wap\controller;

use think\facade\Db;
use think\facade\Request;
use app\common\model\FabricMain as M;
use app\common\model\SupplierMain as SM;
use app\common\model\FabricColor as Color;
use app\common\model\PurchaseInfo as PUR_INFO;

class Fabric extends Base{
	private $tableName='fabric_main';
	
	protected $middleware = ['WapFabric'];

	public function index(){
		if (Request::isAjax()) {
		        $data = $this->getJson(M::getList());
		    return $data;
		}
        
        //利民要拿的版布和A4
        $limin_list=PUR_INFO::listMerge(0,[
            ['info.unit','<>','条'],
            ['info.exp_name','=','利民'],
            ['main.status','=',1],
            ['main.delete_time','=',null]
        ],'');
        // p($limin_list);

		return $this->fetch('',[
            'supplier_list'=>SM::listData(),
            'limin_list'=>$limin_list,
        ]);

	}

	public function info(){
		$id=I('id');
		$T=M::info(['id'=>$id,'uuid'=>$this->uuid],true);
		if($T!=''){
			return $this->fetch('',[
				'T'=>$T
			]);
		}else{
			$this->error('该面料不存在！');
		}
	}

	//颜色列表
	public function color(){
		$id=I('id');
		$source=I('source',1);		//0 是隐藏  1是显示
		$T=Color::listData(['fabric_id'=>$id],'sort asc,color_code asc',1,2000);
		if(count($T)<=0){
			$this->error('暂无颜色！');
		}
		
		if(isMobile()){
			$price=1;
			$terminal='wap';
			$col=4;
		}else{
			$price=0;
			$terminal='pc';
			$col=5;
		}

		//后补的数量
		$lastcount=$col-(count($T)%$col);

		return $this->fetch('',[
			'terminal'=>$terminal,
			'col'=>$col,
			'price'=>$price,				//是否显示价格
			'source'=>$source,				//是否显示原色号
			'lastcount'=>$lastcount,
			'id'=>$id,
			'T'=>$T,
		]);
	}


	//相似罗纹颜色
	public function equal(){
		
		$hex=I('get.hex');
		$T=$this->analogyColor('#'.$hex,15,'b.tid=9');
		if(isMobile()){
			$terminal='wap';
			$col=4;
		}else{
			$terminal='pc';
			$col=5;
		}

		//后补的数量
		$lastcount=$col-(count($T)%$col);

		$hex=$hex;
		$num=I('get.num');
		$cid=I('get.cid');
		return $this->fetch('',[
			'hex'=>$hex,
			'num'=>$num,
			'cid'=>$cid,
			'terminal'=>$terminal,	
			'col'=>$col,
			'lastcount'=>$lastcount,
			'T'=>$T,
		]);
	}
    
    // 计算器
    public function calculate(){
        return $this->fetch('');
    }
}
?>